<!--
  Copyright 2015-2018 the original author or authors.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<div ng-form
     gt-form-with-primary-button>
    <div class="d-inline gt-header-menu gt-header-smaller-menu">
      <div class="dropdown">
        <button type="button"
                class="btn btn-secondary dropdown-toggle"
                data-toggle="dropdown"
                id="gtChartRange"
                aria-haspopup="true"
                aria-expanded="false"
                style="font-size: 1.5rem !important; padding-right: 1rem;">
          {{timeDisplay()}}
        </button>
        <div class="dropdown-menu dropdown-menu-right"
             aria-labelledby="gtChartRange">
          <a class="dropdown-item"
             ng-repeat="last in rangeSelections"
             ng-href="{{currentTabUrl()}}{{headerRangeQueryString(last)}}"
             ng-click="updateLast(last, $event)">
            {{lastDisplay(last)}}
          </a>
          <button type="button"
                  class="dropdown-item"
                  ng-click="openCustomRange()">
            Custom range...
          </button>
        </div>
      </div>
    </div>
</div>
<div class="modal"
     role="dialog"
     tabindex="-1"
     id="customDateRangeModal">
  <div class="modal-dialog modal-dialog-centered"
       role="document"
       style="max-width: 500px;">
    <div class="modal-content">
      <div ng-form
           gt-form-with-primary-button>
        <div class="modal-header">
          <h4 class="modal-title">Custom date range</h4>
          <button type="button"
                  class="close"
                  data-dismiss="modal"
                  aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <div class="container">
            <fieldset class="form-group" style="border: none;">
              <legend style="margin-bottom: 0; font-size: 14px; font-weight: 700;">From</legend>
              <div>
                <!-- margin-bottom is for small screen where time wraps to next line -->
                <div style="width: 12em; float: left; margin-right: 10px; margin-bottom: 10px;">
                  <div class="input-group date" id="customDateRangeFromDate" data-target-input="nearest">
                    <input type="text"
                           class="form-control datetimepicker-input"
                           data-target="#customDateRangeFromDate"
                           aria-label="Date">
                    <div class="input-group-append"
                         data-target="#customDateRangeFromDate"
                         data-toggle="datetimepicker">
                      <div class="input-group-text"><i class="fas fa-calendar"></i></div>
                    </div>
                  </div>
                </div>
                <div style="width: 10em; float: left;">
                  <div class="input-group date" id="customDateRangeFromTime" data-target-input="nearest">
                    <input type="text"
                           class="form-control datetimepicker-input"
                           data-target="#customDateRangeFromTime"
                           aria-label="Time">
                    <div class="input-group-append"
                         data-target="#customDateRangeFromTime"
                         data-toggle="datetimepicker">
                      <div class="input-group-text"><i class="fas fa-clock"></i></div>
                    </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <fieldset class="form-group" style="border: none;">
              <legend style="margin-bottom: 0; font-size: 14px; font-weight: 700;">To</legend>
              <div>
                <!-- margin-bottom is for small screen where time wraps to next line -->
                <div style="width: 12em; float: left; margin-right: 10px; margin-bottom: 10px;">
                  <div class="input-group date" id="customDateRangeToDate" data-target-input="nearest">
                    <input type="text"
                           class="form-control datetimepicker-input"
                           data-target="#customDateRangeToDate"
                           aria-label="Date">
                    <div class="input-group-append"
                         data-target="#customDateRangeToDate"
                         data-toggle="datetimepicker">
                      <div class="input-group-text"><i class="fas fa-calendar"></i></div>
                    </div>
                  </div>
                </div>
                <div style="width: 10em; float: left;">
                  <div class="input-group date" id="customDateRangeToTime" data-target-input="nearest">
                    <input type="text"
                           class="form-control datetimepicker-input"
                           data-target="#customDateRangeToTime"
                           aria-label="Time">
                    <div class="input-group-append"
                         data-target="#customDateRangeToTime"
                         data-toggle="datetimepicker">
                      <div class="input-group-text"><i class="fas fa-clock"></i></div>
                    </div>
                  </div>
                </div>
              </div>
            </fieldset>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
          <button type="button" class="btn btn-primary" ng-click="applyCustomDateRange()">Apply</button>
        </div>
      </div>
    </div>
  </div>
</div>
